
mini.parse();
var editForm = document.getElementById("tableInfoForm");
var form = new mini.Form("tableInfoForm");
//页面初始化
$(function(){
	
})
//流程版本控制
function processVersionControl(row_uid){
    	var row = formGrid.getRowByUID(row_uid);
    	console.log(row);
    	$.ajax({
    		url: '',
    		type: 'POST',
    		success: function(data){
    			console.log(data);
    			if (data.type) {
    				mini.open({
    		            url: url +"activiti/datagridDetail/processVersionControl.html",
    		            title: "流程历史版本", width: 600, height: 400,
    		            onload: function () {
    		                var iframe = this.getIFrameEl();
    		                var data = { action: "edit", id: row.modularId };
    		                iframe.contentWindow.SetData(data);
    		            },
    		            ondestroy: function (action) {
    		            	console.log(action);
    		            }
    		        });
    			} else {
    		        mini.alert("1111");
    		    }    
    		},
    		error: function(data){
    			console.log('请求失败');
    		}
    	})
}
//创建新流程
function addActiviti(row_uid) {
    var row = formGrid.getRowByUID(row_uid);
    if(!row.processId){
    	//名字，id
        addWindow.show();
        rowId = row.formListId;
    }else{
    	mini.alert('当前已有流程');
    }
}
//关联已有流程
function relationActiviti_(row_uid) {
	//弹出窗口路径前缀
	var url = bootPATH + "../frame/frame1/pages/";
    var row = formGrid.getRowByUID(row_uid);
    if (!row.processId) {
    	//打开审批页面
        mini.open({
            url: url +"activiti/activiti_form_list.html",
            title: "流程参照",
            width: 600,
            height: 500,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = {
                    action: "relation",
                    formListId : row.formListId
                };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
            	formGrid.reload();
            }
        });
    }else{
    	mini.alert('当前已有流程');
    }
}
//编辑流程
function editActiviti(row_uid) {
    var row = formGrid.getRowByUID(row_uid);
    if(row.processId){
    	var processId = row.processId;
    	var processName = row.processName;
    	window.location.href = ajaxUrl + "/modeler.html?modelId="+processId;
    }else{
    	mini.alert('当前无流程,请先创建模型');
    }
}
//发布
function releaseActiviti(row_uid) {
    var row = formGrid.getRowByUID(row_uid);
    var processId = row.processId;
	var formListId = row.formListId;
//	//打开审批页面
//    mini.open({
//        url: url +"activiti/datagridDetail/releaseActiviti.html",
//        title: "流程发布",
//        width: 360,
//        height: 200,
//        onload: function () {
//            var iframe = this.getIFrameEl();
//            var data = {
//                action: "relation",
//                formListId: formListId,
//                processId : processId
//            };
//            iframe.contentWindow.SetData(data);
//        },
//        ondestroy: function (action) {
//        	console.log(action);
//        	//formGrid.reload();
//        }
//    });
    if(row.processId){
    	var processId = row.processId;
    	var formListId = row.formListId;
    	$.ajax({
	    	url: ajaxUrl + "/activitiFormController/deploy.do",
	        type:"post",
	        data: {
	        	formId: formListId,
	        	modelId: processId
	        },
	        success: function (data) {
	        	console.log(data);
	        	if(data.type == "error"){
	        		mini.alert(data.msg + ',请先编辑流程')
	        	}else{
	        		mini.alert(data.msg);
		        	formGrid.reload();
	        	}
	        },
	        error: function () {
	            mini.alert("失败");
	        }
	    })
    }else{
    	mini.alert('当前无流程,请先创建模型');
    }
}
//删除当前流程
function removeActiviti(row_uid){
	var row = formGrid.getRowByUID(row_uid);
	if(row.processId){
		mini.confirm('确定删除当前流程','系统提示',function(action){
			if(action == 'ok'){
				var formListId = row.formListId;
		    	$.ajax({
			    	url: ajaxUrl + "/activitiFormController/deleteProcessId.do",
			        type:"post",
			        data: {
			        	formListId: formListId
			        },
			        success: function (data) {
			        	console.log(data);
			        	if(data.type == 'success'){
			        		formGrid.reload();
			        	}else{
			        		mini.alert(data.msg);
			        	}
			        },
			        error: function () {
			            mini.alert("失败");
			        }
			    })
			}
		})
    }else{
    	mini.alert('当前无流程,请先创建模型');
    }
}
//查看流程图
function seeActivitiImg(row_uid) {
    var row = formGrid.getRowByUID(row_uid);
    console.log(row);
    if (row.processId) {
    	var formListId = row.formListId;
        fileUrl = ajaxUrl + "/activitiFormController/showView.do?formId="+formListId;
        images = document.getElementById("imgs")
        images.src = fileUrl;
        var process = document.getElementById("process");
        console.log(process);
        process.style.display = "block";
    }else{
    	mini.alert('当前无流程');
    }
}